using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {
	
	public static LevelManager Instance;

	private float EIGHT 				= 0.125F;
	private float TEN					= 0.1F;
	private float TWELVE 				= 0.083F;
	private float FIFTEEN 				= 0.067F;
	private float EIGHTEEN 				= 0.056F;
	private float TWENTY 				= 0.05F;
	
	public float MULTIPLIER				= default(float);
	
	private float[] mapMultiplier		= { 0.125F	,
											0.1F	,
											0.083F	,
											0.067F	,
											0.056F	,
											0.05F 	};
	public enum MAP_SLICES
	{
		EIGHT							= 0,
		TEN								= 1,
		TWELVE							= 2,
		FIFTEEN							= 3,
		EIGHTEEN						= 4,
		TWENTY							= 5
	};
	
	public enum MAX_TIME
	{
		NINETY							= 90,
		ONETWENTY						= 120,
		ONEFOURTYFOUR					= 144,
		ONEEIGHTY						= 180,
		TWOFORTY						= 240,
		THREEHUNDRED					= 300
	};
	
	public enum VICTORY_TIME
	{
		SIXTY							= 60,
		SEVENTYFIVE						= 75,
		NINETY							= 90,
		ONETWENTY						= 120,
		ONEFIFTY						= 150,
		ONESIXTY						= 160,
		ONEEIGHTY						= 180	
	};
	
	public MAX_TIME maxTime 			= MAX_TIME.NINETY;
	public VICTORY_TIME victoryTime 	= VICTORY_TIME.SIXTY;
	
	public MAP_SLICES mapSlices			= MAP_SLICES.EIGHT;
	
	public float startTime				= 0.0F;
	public float endTime 				= 0.0F;
	
	public float defaultTime 			= 0.0F;
	public float currentTime			= 0.0F;
	
	public UILabel timer				= default ( UILabel );
	
	private bool raceEnd				= false;

	void Awake () 
	{
		Instance = this;
		MULTIPLIER = mapMultiplier[(int)mapSlices];
		
		endTime = (float)maxTime;
		defaultTime = (float)victoryTime;
		
		StartCoroutine("Timer");
	}

	IEnumerator Timer ()
	{
		while( !raceEnd )
		{
			startTime += Time.deltaTime;
			timer.text = Mathf.Round( startTime ).ToString();
			yield return 0;
		}
	}
	
	public void FinishRace ()
	{
		raceEnd = true;
		StopCoroutine ( "Timer" ); 
		currentTime = Mathf.Round( startTime ); 
		
		ScreenManager.Instance.CallResultScreen();
	}
	
}
